@extends('layouts.app')

@section('title', '订单列表')

@section('css-import')
<link href="{{config('app.inlet_src')}}/assets/css/bootstrap-datetimepicker.min.css" rel="stylesheet" media="screen">
@endsection

@section('css-write')
<style type="text/css">
	.page-s{
		float:right;
		display: inline-block;
		padding-bottom: 0px;
		margin: 29px 9px;
		border-radius: 4px;
	}
</style>
@endsection

@section('content-fluid')

<div class="row">
	<!-- BASIC TABLE -->
	<div class="panel">
		<div class="panel-heading">
			<h3 class="panel-title">饭卡出售记录</h3>
		</div>
		<div class="panel-body">
			<ul class="nav nav-pills" style="float:left;">
			  <li role="presentation" class="yizhifu"><a href="/cardSellorder?pay=zhifu&circle_range_id={{$_GET["circle_range_id"] ?? ""}}">已支付</a></li>
			  <li role="presentation" class="weizhifu"><a href="/cardSellorder?pay=weizhifu&circle_range_id={{$_GET["circle_range_id"] ?? ""}}">未支付</a></li>
			  <li role="presentation" class="orderall"><a href="/cardSellorder">全部</a></li>
			</ul>
			<div class="input-group date form_datetime col-md-2" data-date="{{date('Y-m-d H:i')}}" data-date-format="yyyy-mm-dd hh:ii" data-link-field="dtp_input1" style="float:left; margin-left:25px;">
			    <input class="form-control" size="16" type="text" value="{{$_GET['starttime'] ?? ''}}" name="starttime" placeholder="筛选从...开始" readonly>
			    <span class="input-group-addon"><span class="glyphicon glyphicon-remove"></span></span>
				<span class="input-group-addon"><span class="glyphicon glyphicon-th"></span></span>
			</div>
			<div class="input-group date form_datetime col-md-2" data-date="{{date('Y-m-d H:i')}}" data-date-format="yyyy-mm-dd hh:ii" data-link-field="dtp_input1" style="float:left; margin-left:20px;">
			    <input class="form-control" size="16" type="text" value="{{$_GET['endtime'] ?? ''}}" placeholder="筛选到...结束" name="endtime" readonly>
			    <span class="input-group-addon"><span class="glyphicon glyphicon-remove"></span></span>
				<span class="input-group-addon"><span class="glyphicon glyphicon-th"></span></span>
			</div>
			<table class="table table-hover">
				<thead>
					<tr>
						<th>#</th>
						<th>订单号</th>
						<th>下单用户</th>
						<th>套餐</th>
						<th>消费金额</th>
						<th>手机号</th>
						<th>下单时间</th>
						<th>订单状态</th>
						<th>推荐人</th>
						<th>商圈</th>
						<th class="{{power_if('*')}}">操作</th>
					</tr>
				</thead>
				<tbody>
					@foreach($orders as $k=>$v)
					<tr>
						<td class="order_id_c">{{$v->order_id}}</td>
						<td class="ordernumber">{{$v->order_num}}</td>
						<td><a href="/user-details?userid={{$v->user_id}}">{{$v->nicename ?? '未填写'}}</a></td>
						<td>{{$v->card_name}}</td>
						<td>{{$v->order_price/100}} 元</td>
						<td>{{$v->tel}}</td>
						<td>{{$v->insert_time}}</td>
						<td>{{$orderstatus_de[$v->order_status]}}</td>
						<td><a href="/user-details?userid={{$v->share_userid}}">{{$v->share_user_name ?? '无'}}</a></td>
						<td>{{$v->sucircle_name}}</td>

						<td class="{{power_if('*')}}">@if($v->order_status==1)<a href="javascript:;" class="tuikuan">全额退款</a>@endif</td>
					</tr>
					@endforeach
				</tbody>
			</table>
			{{ $orders->appends(['starttime' => $_GET['starttime']??'','endtime'=>$_GET['endtime']??'','pay'=>$_GET['pay']??'','circle_range_id'=>$_GET['circle_range_id']??''])->links() }} 
			<div class="page-s">本页共{{ $orders->count() }}条</div>
			<div class="page-s">共{{ $orders->total() }}条</div>
			<div class="page-s">当前第{{ $orders->currentPage() }}页</div>
			<div class="page-s">共{{ $orders->lastPage() }}页</div>
			<div class="page-s">已支付订单{{ $successorder }}条</div>
		</div>
	</div>
	<!-- END BASIC TABLE -->
</div>
@endsection

@section('js-import')
<script src="{{config('app.inlet_src')}}/assets/scripts/bootstrap-datetimepicker.js"></script>
<script src="{{config('app.inlet_src')}}/assets/scripts/bootstrap-datetimepicker.zh-CN.js"></script>
@endsection

@section('js-write')
<script type="text/javascript">

	$('.tuikuan').click(function(){
		var this_ = $(this);
		swal({
		  title: '确定执行退款操作吗', 
		  text: '退款后将把款项全额退回，执行后将无法恢复！', 
		  type: 'question',
		  showCancelButton: true, 
		  confirmButtonColor: '#3085d6',
		  cancelButtonColor: '#d33',
		  confirmButtonText: '确定', 
		  cancelButtonText: '取消',
		  confirmButtonClass: 'btn btn-success',
		  cancelButtonClass: 'btn btn-danger',
		  buttonsStyling: true
		}).then(function(al) {
			if(al.value){
				$.ajaxSetup({
				    headers: {
				        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
				    }
				});
				$.post('/meal/card/tuikuan',{'order_id':this_.parents('tr').find('.order_id_c').html()},function(response){
					if(response.success){
						toastr.success(response.message);
					}else{
						toastr.error(response.message);
					}
				},'json');
			}
		});
		
	});
    $('.form_datetime').datetimepicker({
        language:  'zh-CN',
        weekStart: 1,
        todayBtn:  1,
		autoclose: 1,
		todayHighlight: 1,
		startView: 2,
		forceParse: 0,
        showMeridian: 1
    });
	var pay = getQueryString('pay');
	if(pay){
		if(pay=='zhifu'){
			$('.yizhifu').addClass('active');
		}else if(pay=='weizhifu'){
			$('.weizhifu').addClass('active');
		}
	}else{
		$('.orderall').addClass('active');
	}
	var im = 0;
	var ie = 0;
	var u = '/cardSellorder';
	$('input[name="starttime"]').change(timeEdit);
	$('input[name="endtime"]').change(timeEdit);
	function timeEdit(){
		var end_v = $('input[name="endtime"]').val();
		var start_v = $('input[name="starttime"]').val();
		if($(this).attr('name')=='starttime'){
			im += 1;
		}
		if($(this).attr('name')=='endtime'){
			ie += 1;
		}
		if(ie>0 && im>0){
			if(pay){
				location.href = u+'?pay='+pay+'&starttime='+start_v+'&endtime='+end_v+'&circle_range_id={{$_GET["circle_range_id"] ?? ""}}';
			}else{
				location.href = u+'?starttime='+start_v+'&endtime='+end_v+'&circle_range_id={{$_GET["circle_range_id"] ?? ""}}';
			}
		}
	}
</script>
@endsection
